import { createRouter, createWebHistory } from 'vue-router'
import loginRoutes from './login'
import LayoutContainer from './user/layoutContainer'
import adminLayoutContainer from './admin/layoutContainer'
import { useUserStore } from '@/stores/index'
import { adminUserStore } from '@/stores/index'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [...loginRoutes, ...LayoutContainer, ...adminLayoutContainer]
})
//路由守卫

router.beforeEach(async (to) => {
  const useStore = useUserStore()
  const adminStore = adminUserStore()

  if (!adminStore.token && !useStore.token && to.path !== '/') {
    // 重定向到登录页面
    return { path: '/' }
  }
})
export default router
